package cn.geminis.resources.service.model;

import cn.geminis.lowcode.annotation.CrudController;
import cn.geminis.lowcode.annotation.CrudRepository;
import cn.geminis.lowcode.annotation.QueryFilter;
import cn.geminis.lowcode.annotation.UuidEntity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToMany;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.util.HashSet;
import java.util.Set;

/**
 * @author puddi
 */
@Setter
@Getter
@UuidEntity
@DynamicInsert
@DynamicUpdate
@QueryFilter
@CrudRepository
@CrudController
public class Role {

    @Column(nullable = false, length = 32)
    private String name;

    @Column(nullable = false)
    private int showOrder;

    @ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE})
    private Set<Function> functions = new HashSet<>();

    @ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE})
    private Set<Role> rolesManage = new HashSet<>();

    @JsonBackReference
    public Set<Role> getRolesManage() {
        return rolesManage;
    }

}
